//
//  DZRoomDetailTableViewCell.m
//  DaZhePrivateHomeCuisineClient
//
//  Created by zouzhisheng on 14-12-15.
//  Copyright (c) 2014年 zouzhisheng. All rights reserved.
//

#import "DZRoomDetailTableViewCell.h"
#import "DZZanModel.h"
#import "DZPicDetailViewController.h"
#import "DZZanManager.h"
@implementation DZRoomDetailTableViewCell

- (void)awakeFromNib
{
    // Initialization code
    self.contentView.backgroundColor=[UIColor colorWithHexString:@"ECECEC"];
    self.zanImageView.layer.borderColor=[UIColor whiteColor].CGColor;
    self.zanImageView.layer.cornerRadius=5;
    self.zanImageView.layer.borderWidth=1.0;
    self.nameLabel.textColor=[UIColor colorWithHexString:@"595757"];
    self.adressLabel.textColor=[UIColor colorWithHexString:@"3e3a39"];
    self.adressLabel.numberOfLines=0;
    self.tel1Label.textColor=[UIColor colorWithHexString:@"3e3a39"];
    self.zanNumLabel.textColor=[UIColor colorWithHexString:@"FF8D33"];
    self.zanLabel.textColor=[UIColor colorWithHexString:@"FF8D33"];
    UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toBigView)];
    self.detailImageView.userInteractionEnabled=YES;
    [self.detailImageView addGestureRecognizer:tap];
    [self.gudingPhone setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    [self.mobille setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
- (IBAction)zanAction:(id)sender {
    /**
     2.7点赞管理的接口
     http://www.tongliaochihuo.com/interface/addZanInfo.php?act=zan&sid=3
     Params：sid为餐馆id
     
     **/
    if (![[DZZanManager shareZanManager] addZan:self.sid]) {
        return;
    }
    UIButton *bt=(UIButton*)sender;
     NSDictionary *paramDir=[NSDictionary dictionaryWithObjectsAndKeys:@"zan",@"act",self.sid,@"sid", nil];
    [[BaseService shareNetworkService] requestActivityParameters:paramDir DataSouce:nil RequestType:Request_DaZheDianZan Block:^(__weak id data, NSError *error) {
        if (!error) {
            DZZanModel *model=data;
            if ([model.success isEqualToString:@"true"]) {
              self.zanNumLabel.text=[NSString stringWithFormat:@"%d",[self.zanNumLabel.text intValue]+1];
            }
            
        }
    
    }];

}

- (IBAction)phoneAction:(id)sender {
    UIButton *bt=(UIButton*)sender;
    self.telNum=bt.currentTitle;
    NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"telprompt://%@",self.telNum];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];

}
-(void)loadData:(DZRestanutantDetailSubModel *)model{
//    [self.bgImageBt sd_setBackgroundImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/%@",API_DOMAIN,model.thumb]] forState:UIControlStateNormal placeholderImage:IMG(@"pic")];
    self.restanutantDetailSubModel=model;
    DZThumbStr *subModel=model.thumb[0];
    [self.detailImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/%@",API_DOMAIN,subModel.picPath]] placeholderImage:IMG(@"pic")];
    self.nameLabel.text=model.name;
    self.adressLabel.text=[NSString stringWithFormat:@"地址: %@",model.address];
    [self.gudingPhone setTitle:model.tel forState:UIControlStateNormal];
    [self.mobille setTitle:model.c_tel1 forState:UIControlStateNormal];
    if (model.c_tel1.length==0) {
        self.phone1.hidden=YES;
    }
    if (model.tel.length==0) {
        self.phone2.hidden=YES;
    }
    self.zanNumLabel.text=model.c_zan;
    self.sid=model.sid;
}
-(void)toBigView{
    UIViewController *vc=[self viewController];
    DZPicDetailViewController *picDetail=[[DZPicDetailViewController alloc] init];
    picDetail.imageArray=self.restanutantDetailSubModel.thumb;
    [vc.navigationController pushViewController:picDetail animated:YES];
}
- (UIViewController*)viewController {
    for (UIView* next = [self superview]; next; next =
         next.superview) {
        UIResponder* nextResponder = [next nextResponder];
        if ([nextResponder isKindOfClass:[UIViewController
                                          class]]) {
            return (UIViewController*)nextResponder;
        }
    }
    return nil;
}

@end
